//
//  GMHomeTableViewCell.m
//  Teecloud
//
//  Created by 小熊 on 2018/6/13.
//  Copyright © 2018年 小熊. All rights reserved.
//

#import "GMHomeTableViewCell.h"
@interface GMHomeTableViewCell()
@property (weak, nonatomic) IBOutlet UIImageView *Img;
@property (weak, nonatomic) IBOutlet UILabel *Name;
@property (weak, nonatomic) IBOutlet UIButton *biaoqian;
@property (weak, nonatomic) IBOutlet UILabel *time;
@property (weak, nonatomic) IBOutlet UILabel *price;
@property (weak, nonatomic) IBOutlet XHStarRateView *starView;
@property (weak, nonatomic) IBOutlet UIImageView *shareImg;

@end
@implementation GMHomeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.starView.rateStyle = XHStarRateViewRateStyeHalfStar; //半星评分；
}
-(void)setStuModel:(GMStudyResModel *)stuModel{
    _stuModel = stuModel;
    [self.Img yy_setImageWithURL:[NSURL URLWithString:stuModel.HeadUrl] placeholder:DefealtImg];
    self.Name.text = stuModel.Name;
    self.starView.currentRating = stuModel.AvgScore/2;
    
    self.shareImg.hidden = YES;
    if (stuModel.NormalCode >0 && stuModel.NormalCode <= 2) {
         self.shareImg.hidden = NO;
        self.shareImg.image =[UIImage imageNamed:@"exception-corner-red"];
    }else if (stuModel.NormalCode == 3){
        self.shareImg.hidden = NO;
        self.shareImg.image =[UIImage imageNamed:@"over-corner-orange"];
    }else{
        if (stuModel.IsBuyed && stuModel.IsShare) {
            self.shareImg.hidden = NO;
            self.shareImg.image =[UIImage imageNamed:@"share-corner-green"];
        }else{
            self.shareImg.hidden = YES;
        }
    }
    if (stuModel.IsBuyed) {
//        self.price.text = @"已购";
//        self.price.backgroundColor = kWhiteColor;
//        self.price.textColor = kDarkGrayColor;
//        self.price.layer.borderColor = kDarkGrayColor.CGColor;
//        self.price.layer.borderWidth = 1;
    }else{
        if ([stuModel.Price isEqual:@(0)]) {
//            self.price.text = @"免费";
//            self.price.backgroundColor = kWhiteColor;
//            self.price.textColor = kDarkGrayColor;
//            self.price.layer.borderColor = kWhiteColor.CGColor;
//            self.price.layer.borderWidth = 0;
        }else{
//            self.price.text = @"";
//            self.price.text = [NSString stringWithFormat:@"%@元",stuModel.Price];
//            self.price.backgroundColor = kWhiteColor;
//            self.price.textColor = [UIColor colorWithHexString:@"FF7708"];
//            self.price.layer.borderColor = kWhiteColor.CGColor;
//            self.price.layer.borderWidth = 0;
        }
    }
    if ([stuModel.ResTypeName isEqualToString:@"课程包"]) {
        self.biaoqian.layer.borderWidth =1.0;
        self.biaoqian.layer.borderColor =kRedColor.CGColor;
        [self.biaoqian setTitleColor:kRedColor forState:0];
        self.biaoqian.layer.cornerRadius=5;
    }else{
        self.biaoqian.layer.borderWidth =1.0;
        self.biaoqian.layer.borderColor =[UIColor colorWithHexString:@"FF7708"].CGColor;
        [self.biaoqian setTitleColor:[UIColor colorWithHexString:@"FF7708"] forState:0];
        self.biaoqian.layer.cornerRadius=5;
    }
    [self.biaoqian setTitle:[NSString stringWithFormat:@"  %@  ",stuModel.ResTypeName] forState:UIControlStateNormal] ;
    if ([stuModel.ResType isEqualToNumber:@(1)]) {
        /**视频*/
         self.time.text = [NSString stringWithFormat:@"%@分钟",stuModel.TimeLen];
    }else if ([stuModel.ResType isEqualToNumber:@(2)]){
        /**文档*/
         self.time.text = [NSString stringWithFormat:@"%@页",stuModel.PageCount];
    }else if ([stuModel.ResType isEqualToNumber:@(3)]){
        /**习题*/
         self.time.text = [NSString stringWithFormat:@"%@题",stuModel.ExerCount];
    }else if ([stuModel.ResType isEqualToNumber:@(4)]){
        /**试卷*/
         self.time.text = [NSString stringWithFormat:@"%@题",stuModel.ExerCount];
    }else if ([stuModel.ResType isEqualToNumber:@(9)]){
        /**课程包*/
         self.time.text = [NSString stringWithFormat:@"%@资源",stuModel.PageCount];
    }
   
}


@end
